﻿Public Class u_ThanhToanHoaDon

    Private Sub LoadData()
        Dim hd As New HoaDonBUS
        dvgHoaDon.DataSource = hd.GetHoaDon
        Dim nhom As New NhanVienBUS
        cbxTenNV.DataSource = nhom.GetNhanVien
        cbxTenNV.DisplayMember = "TenNV"
        cbxTenNV.ValueMember = "MaNV"
        cbxTenNV.SelectedIndex = 0
        Dim tv As New KhachHangBUS
        cbxKhachHang.DataSource = tv.GetKhachHang
        cbxKhachHang.DisplayMember = "TenKH"
        cbxKhachHang.ValueMember = "MaKH"
        cbxKhachHang.SelectedIndex = 0
        Dim mb As New BanBUS
        cbxMaBan.DataSource = mb.GetBan
        cbxMaBan.DisplayMember = "MaBan"
        cbxMaBan.ValueMember = "MaBan"
        cbxMaBan.SelectedIndex = 0
    End Sub

    Private Sub u_NhaCungCap_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadData()
    End Sub

    Private Sub btnThem_Click(sender As Object, e As EventArgs) Handles btnThem.Click
        Dim newHD As New HoaDonDTO
        newHD.MaHD = txtMaHD.Text
        newHD.NgayXuat = ThoiGian.Value.Date
        newHD.MaBan = cbxMaBan.SelectedValue
        newHD.MonAnThanhToan = txtMon.Text
        newHD.MaNV = cbxTenNV.SelectedValue
        newHD.TinhTrang = cbDa.Checked
        newHD.MaKH = cbxKhachHang.SelectedValue
        Dim hdBUS As New HoaDonBUS
        hdBUS.AddHoaDon(newHD)
        LoadData()
    End Sub

    Private Sub dgvHoaDon_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles dgvHoaDon.FocusedRowChanged
        txtMaHD.Text = dgvHoaDon.GetRowCellValue(dgvHoaDon.FocusedRowHandle, "MaHD")
        ThoiGian.Text = dgvHoaDon.GetRowCellValue(dgvHoaDon.FocusedRowHandle, "NgayXuat")
        cbxMaBan.Text = dgvHoaDon.GetRowCellValue(dgvHoaDon.FocusedRowHandle, "MaBan")
        txtMon.Text = dgvHoaDon.GetRowCellValue(dgvHoaDon.FocusedRowHandle, "TenMonAn")
        cbxTenNV.SelectedValue = dgvHoaDon.GetRowCellValue(dgvHoaDon.FocusedRowHandle, "MaNV")
        cbxKhachHang.SelectedValue = dgvHoaDon.GetRowCellValue(dgvHoaDon.FocusedRowHandle, "MaKH")
        txtTongTien.Text = dgvHoaDon.GetRowCellValue(dgvHoaDon.FocusedRowHandle, "TongTien")
    End Sub

    Private Sub btnXoa_Click(sender As Object, e As EventArgs) Handles btnXoa.Click
        Dim delHD As New HoaDonDTO
        delHD.MaHD = dgvHoaDon.GetRowCellValue(dgvHoaDon.FocusedRowHandle, "MaHD")
        Dim hdBUS As New HoaDonBUS
        hdBUS.DelHoaDon(delHD)
        LoadData()
    End Sub

    Private Sub btnCapNhat_Click(sender As Object, e As EventArgs) Handles btnCapNhat.Click
        Dim newHD As New HoaDonDTO
        newHD.MaHD = dgvHoaDon.GetRowCellValue(dgvHoaDon.FocusedRowHandle, "MaHD")
        newHD.NgayXuat = ThoiGian.Text
        newHD.MaBan = cbxMaBan.Text
        newHD.MonAnThanhToan = txtMon.Text
        newHD.MaNV = cbxTenNV.SelectedValue
        newHD.MaKH = cbxKhachHang.SelectedValue
        newHD.TongTien = txtTongTien.Text
        Dim hdBUS As New HoaDonBUS
        hdBUS.UpdateHoaDon(newHD)
        LoadData()
    End Sub
End Class
